|
|
|
|
|
|
|
Listing 26.1 shows the use of the FindFirst method to look for records based on user-defined criteria. |
|
|
|
|
|
|
|
|
Listing 26.1 FINDTEST.TXTUsing FindFirst to Look for a Record |
|
|
|
|
|
|
|
|
Private Sub cmdFindFirst_Click()
Dim sCriteria As String
Dim sBkmark As String
'Build the criteria string
sCriteria = "title like '*" & txtFind.Text & "*'"
'Remember where we were in case Find fails
sBkmark = rsTitles.Bookmark
'Execute the Find
rsTitles.FindFirst sCriteria
'Check for success
If rsTitles.NoMatch Then
MsgBox "Record not found!"
'If failed, return to last good record
rsTitles.Bookmark = sBkmark
End If
'Fill the text boxes
ShowFields
End Sub |
|
|
|
|
| |
|
|
|
|
In many cases, re-creating a dynaset using the search criteria is faster than using the Find methods to process all matching records. You can also create a second filtered dynaset from the first dynaset by using the search criteria as the filter condition. The best technique depends on the amount of data, size of each record, as well as other factors. Try different approaches with your data to see what's best for a given situation. |
|
|
|
|
|
 |
|
 |
|
|
Cannot bind . . . Error |
|
|
|
 |
|
 |
|
|
When you use variables as the value to be compared to, you might encounter the error Cannot bind name item when you run the program. When the field and the variable you are comparing are string (or text) variables, surround the variable name with single quotation marks ('), as shown in the following sample code: |
|
|
|
 |
|
 |
|
|
Dim sFindCrit As String, sFindStr As String
sFindStr = "Smith"
sFindCrit = "Lastname = '" & FindStr & "'"
rsTest.FindFirst FindCrit |
|
|
|
 |
|
 |
|
|
For the sake of readability, you can also assign the single quotation mark to a constant and use that constant in your code. |
|
|
|
 |
|
 |
|
|
In the same manner, surround a date variable with the pound symbol (#) to compare it to a date field. You don't need to include any additional symbols when comparing numbers. |
|
|
|
|
|